﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace scomA2Proj
{
    public static class ConsoleUtil
    {
        delegate void SetTextCallback(string text);
        public static RichTextBox RichTextBox { get; set; }

        /// <summary>
        /// Appends text to the end.
        /// </summary>
        /// <param name="text"></param>
        public static void AppendText(string text)
        {
            if (RichTextBox.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(ConsoleUtil.AppendLine);
                RichTextBox.Invoke(d, new object[] { text });
            }
            else
            {
                RichTextBox.AppendText(text);
            }
            
        }

        /// <summary>
        /// Appends the text with a new line at the end.
        /// </summary>
        /// <param name="text"></param>
        public static void AppendLine(string text)
        {
            if (RichTextBox.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(ConsoleUtil.AppendLine);
                RichTextBox.Invoke(d, new object[] { text });
            }
            else
            {
                RichTextBox.AppendText(text + "\n");
            }
        }
    }
}
